package com.douqu.game.core.factory;

import com.bean.core.pay.alipay.AlipayConfig;
import com.bean.core.pay.tenpay.bean.TenpayConfig;
import com.douqu.game.core.config.*;
import com.douqu.game.core.config.activity.*;
import com.douqu.game.core.config.battle.*;
import com.douqu.game.core.config.card.*;
import com.douqu.game.core.config.challenge.*;
import com.douqu.game.core.config.drop.DropGroupConfig;
import com.douqu.game.core.config.goods.*;
import com.douqu.game.core.config.hegemony.HegemonyLvDifConfig;
import com.douqu.game.core.config.hegemony.HegemonyRankRewardConfig;
import com.douqu.game.core.config.hegemony.HegemonyRankRewardGroupConfig;
import com.douqu.game.core.config.hegemony.HegemonySkillCountConfig;
import com.douqu.game.core.config.major.MajorConfig;
import com.douqu.game.core.config.major.MajorMergeConfig;
import com.douqu.game.core.config.mall.MallConfig;
import com.douqu.game.core.config.map.*;
import com.douqu.game.core.config.sprite.MasterConfig;
import com.douqu.game.core.config.sprite.MasterParamConfig;
import com.douqu.game.core.config.sprite.SoldierConfig;
import com.douqu.game.core.config.store.GoblinStoreConfig;
import com.douqu.game.core.config.talent.TalentConfig;
import com.douqu.game.core.config.talent.TalentLevelConfig;
import com.douqu.game.core.config.talent.TalentRefineConfig;
import com.douqu.game.core.config.talent.TalentUpConfig;
import com.douqu.game.core.config.task.ActiveBoxConfig;
import com.douqu.game.core.config.task.GrowUpBoxConfig;
import com.douqu.game.core.config.task.TaskConfig;
import com.douqu.game.core.entity.GameObject;
import com.douqu.game.core.util.CoreUtils;
import com.douqu.game.core.util.LoadUtils;
import com.douqu.game.core.util.LogUtils;

import javax.swing.*;
import java.io.*;
import java.text.MessageFormat;
import java.util.*;

/**
 * Author : Bean
 * 2017-07-06 16:13
 */
public class LoadFactory {


    private static boolean testLoad = false;


//    public static JsonObject jsonObject = null;

    /**
     * 配置好就不变的配置路径,spring-boot的配置和center里基本配置
     */
    public static String FIXED_CONFIG_PATH = "";

    /**
     * 会变化的配置路径(比如data目录,日志服里的sql)
     */
    public static String DYNAMIC_CONFIG_PATH = "";


    public static InputStream getInputStream(String filePath)
    {
        InputStream input = null;
        try {
//            if(filePath.endsWith("properties"))
//                input = LoadFactory.class.getClassLoader().getResourceAsStream(filePath);
//            else
//            {
            File file = null;
            try{
                if(filePath.startsWith("C:") || filePath.startsWith("D:")
                        || filePath.startsWith("E:") || filePath.startsWith("F:") || filePath.startsWith("G:"))
                    file = new File(filePath);
                else
                    file = new File(CoreUtils.getBasePath() + filePath);

                if(!file.exists())
                    file = new File(CoreUtils.getRootPath() + filePath);

                if(file.exists())
                {
                    input = new BufferedInputStream(new FileInputStream(file));
                }
                else
                {
                    input = LoadFactory.class.getClassLoader().getResourceAsStream(filePath);
                }

            }catch (Exception e){
                if(filePath.endsWith("properties"))
                    input = LoadFactory.class.getClassLoader().getResourceAsStream(filePath);
            }




//            }

        }catch (Exception e){
            e.printStackTrace();
        }

        return input;
    }
//    public static JsonObject getJsonObject() {
//        return jsonObject;
//    }
//
//    public static void setJsonObject(JsonObject jsonObject) {
//        LoadFactory.jsonObject = jsonObject;
//    }

    public static void loadGameObject(String filePath)
    {
        try{
            String path = DYNAMIC_CONFIG_PATH + filePath;
            LoadFactory.loadGameObject(path, AIConfig.class, DataFactory.AI_KEY);
            LoadFactory.loadGameObject(path, AttributeConfig.class, DataFactory.ATTRIBUTE_KEY);
            LoadFactory.loadGameObject(path, MasterParamConfig.class, DataFactory.MASTER_PARAM_KEY);
            LoadFactory.loadGameObject(path, AssetConfig.class, DataFactory.ASSET_KEY);
            LoadFactory.loadGameObject(path, ProfessionConfig.class, DataFactory.PROFESSION_KEY);
            LoadFactory.loadGameObject(path, BuffConfig.class, DataFactory.BUFF_KEY);
            LoadFactory.loadGameObject(path, SkillConfig.class, DataFactory.SKILL_KEY);
            LoadFactory.loadGameObject(path, MapConfig.class, DataFactory.MAP_KEY);
            LoadFactory.loadGameObject(path, PropConfig.class, DataFactory.PROP_KEY);
            LoadFactory.loadGameObject(path, EquipConfig.class, DataFactory.EQUIP_KEY);
            LoadFactory.loadGameObject(path, AccessoryConfig.class, DataFactory.ACCESSORY_KEY);
            LoadFactory.loadGameObject(path, CardStarAttributeConfig.class, DataFactory.CARD_STAR_ATTRIBUTE_KEY);
            LoadFactory.loadGameObject(path, SoldierConfig.class, DataFactory.SOLDIER_KEY);
            LoadFactory.loadGameObject(path, MasterConfig.class, DataFactory.MASTER_KEY);
            LoadFactory.loadGameObject(path, CardConfig.class, DataFactory.CARD_KEY);
            LoadFactory.loadGameObject(path, CardLvConfig.class, DataFactory.CARD_LV_KEY);
            LoadFactory.loadGameObject(path, CardStarConfig.class, DataFactory.CARD_STAR_KEY);
            LoadFactory.loadGameObject(path, CardFateConfig.class, DataFactory.CARD_FATE_KEY);
            LoadFactory.loadGameObject(path, AccessoryUpConfig.class, DataFactory.ACCESSORY_UP_KEY);
            LoadFactory.loadGameObject(path, AccessoryIntensifyConfig.class, DataFactory.ACCESSORY_INTENSIFY_KEY);
            LoadFactory.loadGameObject(path, MonsterConfig.class, DataFactory.MONSTER_KEY);
            LoadFactory.loadGameObject(path, DropGroupConfig.class, DataFactory.DROP_GROUP_KEY);

            /** 这个要放在 playerLv之前*/
            LoadFactory.loadGameObject(path, InitDataConfig.class, DataFactory.INIT_DATA);

            LoadFactory.loadGameObject(path, PlayerLvConfig.class, DataFactory.PLAYER_LV_KEY);
            LoadFactory.loadGameObject(path, StarCheckConfig.class, DataFactory.STAR_CHECK_KEY);
            LoadFactory.loadGameObject(path, CardParamConfig.class, DataFactory.CARD_PARAM_KEY);
            LoadFactory.loadGameObject(path, LevelConfig.class, DataFactory.LEVEL_KEY);
            LoadFactory.loadGameObject(path, InstanceConfig.class, DataFactory.INSTANCE_KEY);
            LoadFactory.loadGameObject(path, ArenaDailyConfig.class, DataFactory.ARENA_DAILY_REWARD_KEY);
            LoadFactory.loadGameObject(path, ExchangeRewardConfig.class, DataFactory.REWARD_KEY);
            LoadFactory.loadGameObject(path, LotteryConfig.class, DataFactory.LOTTERY_KEY);
            LoadFactory.loadGameObject(path, OfficialRankConfig.class, DataFactory.OFFICIAL_RANK_KEY);
            LoadFactory.loadGameObject(path, OfficialIntegralConfig.class, DataFactory.OFFICIAL_INTEGRAL_REWARD_KEY);
            LoadFactory.loadGameObject(path, AltarConfig.class, DataFactory.ALTAR_KEY);
            LoadFactory.loadGameObject(path, PlayerNameConfig.class, DataFactory.PLAYER_NAME_KEY);
            LoadFactory.loadGameObject(path, GoblinStoreConfig.class, DataFactory.GOBLIN_STORE_KEY);
            LoadFactory.loadGameObject(path, TaskConfig.class, DataFactory.TASK_KEY);
            LoadFactory.loadGameObject(path, GrowUpBoxConfig.class, DataFactory.GROW_UP_BOX_KEY);
            LoadFactory.loadGameObject(path, ActiveBoxConfig.class, DataFactory.ACTIVE_BOX_KEY);
            LoadFactory.loadGameObject(path, EquipIntensifyConfig.class, DataFactory.EQUIP_INTENSIFY_KEY);
            LoadFactory.loadGameObject(path, StableDataConfig.class, DataFactory.STABLE_DATA_KEY);
            LoadFactory.loadGameObject(path, ResolveConfig.class, DataFactory.RESOLVE_DATA_KEY);
            LoadFactory.loadGameObject(path, HeroTempleConfig.class, DataFactory.HERO_TEMPLE_KEY);
            LoadFactory.loadGameObject(path, FunctionConfig.class, DataFactory.FUNCTION_KEY);
            LoadFactory.loadGameObject(path, VipConfig.class, DataFactory.VIP_KEY);
            LoadFactory.loadGameObject(path, RechargeConfig.class, DataFactory.RECHARGE_KEY);
            LoadFactory.loadGameObject(path, PurchaseTimesConfig.class, DataFactory.PURCHASE_KEY);
            LoadFactory.loadGameObject(path, DailySignRewardConfig.class, DataFactory.DAILY_SIGN_KEY);
            LoadFactory.loadGameObject(path, FundRewardConfig.class, DataFactory.FUND_REWARD_KEY);
            LoadFactory.loadGameObject(path, LoginTimesBonusConfig.class, DataFactory.LOGIN_TIMES_REWARD_KEY);
            LoadFactory.loadGameObject(path, MailConfig.class, DataFactory.MAIL_MODEL_KEY);
            LoadFactory.loadGameObject(path, ExpeditionConfig.class, DataFactory.EXPEDITION_KEY);
            LoadFactory.loadGameObject(path, LegionChainConfig.class, DataFactory.LEGION_CHAIN_KEY);
            LoadFactory.loadGameObject(path, MasterTrainConfig.class, DataFactory.MASTER_TRAIN_KEY);
            LoadFactory.loadGameObject(path, MajorConfig.class, DataFactory.MAJOR_KEY);
            LoadFactory.loadGameObject(path, MajorMergeConfig.class, DataFactory.MAJOR_MERGE_KEY);
            LoadFactory.loadGameObject(path, CampRobotConfig.class, DataFactory.CAMP_ROBOT_KEY);
            LoadFactory.loadGameObject(path, ArenaRobotConfig.class, DataFactory.ARENA_ROBOT_KEY);
            LoadFactory.loadGameObject(path, AuctionConfig.class, DataFactory.WORLD_AUCTION_KEY);
            LoadFactory.loadGameObject(path, WorldBossConfig.class, DataFactory.WORLD_BOSS_KEY);
            LoadFactory.loadGameObject(path, WorldBossParameterConfig.class, DataFactory.WORLD_BOSS_PARAM_KEY);
            LoadFactory.loadGameObject(path, MallConfig.class, DataFactory.MALL_STORE_KEY);
            LoadFactory.loadGameObject(path, AdConfig.class, DataFactory.AD_KEY);
            LoadFactory.loadGameObject(path, CityConfig.class, DataFactory.CITY_KEY);
            LoadFactory.loadGameObject(path, CityArmyConfig.class, DataFactory.CITY_ARMY_KEY);
            LoadFactory.loadGameObject(path, CityArmyGroupConfig.class, DataFactory.CITY_ARMY_GROUP_KEY);
            LoadFactory.loadGameObject(path, RechargeGuideItemConfig.class, DataFactory.RECHARGE_GUIDE_ITEM_KEY);
            LoadFactory.loadGameObject(path, RechargeGuideConfig.class, DataFactory.RECHARGE_GUIDE_KEY);
            LoadFactory.loadGameObject(path, TimeLimitedActivitiesConfig.class, DataFactory.TIME_LIMIT_ACTIVITY_KEY);
            LoadFactory.loadGameObject(path, WorldMapTaskConfig.class, DataFactory.WORLD_MAP_TASK);
            LoadFactory.loadGameObject(path, WorldMapTaskGroupConfig.class, DataFactory.WORLD_MAP_TASK_GROUP);
            LoadFactory.loadGameObject(path, WorldMapTaskBoxConfig.class, DataFactory.WORLD_MAP_TASK_BOX);
            LoadFactory.loadGameObject(path, FlashSaleConfig.class, DataFactory.FLASH_SALE_KEY);
            LoadFactory.loadGameObject(path, ShareConfig.class, DataFactory.SHARE_KEY);
            LoadFactory.loadGameObject(path, RankRewardConfig.class, DataFactory.RANK_REWARD_KEY);
            LoadFactory.loadGameObject(path, HegemonySkillCountConfig.class, DataFactory.HEGEMONY_SKILL_COUNT);
            LoadFactory.loadGameObject(path, HegemonyLvDifConfig.class, DataFactory.HEGEMONY_LV_DIF);
            LoadFactory.loadGameObject(path, HegemonyRankRewardGroupConfig.class, DataFactory.HEGEMONY_RANK_REWARD_GROUP);
            LoadFactory.loadGameObject(path, HegemonyRankRewardConfig.class, DataFactory.HEGEMONY_RANK_REWARD);
            LoadFactory.loadGameObject(path, CityDropGroupConfig.class, DataFactory.CITY_DROP_GROUP);
            LoadFactory.loadGameObject(path, CityDropConfig.class, DataFactory.CITY_DROP);
            LoadFactory.loadGameObject(path, RouteConfig.class, DataFactory.ROUTE_KEY);
            LoadFactory.loadGameObject(path, CityExpeditionConfig.class, DataFactory.CITY_EXPEDITION_KEY);
            LoadFactory.loadGameObject(path, OnlineRewardConfig.class, DataFactory.ONLINE_REWARD);
            LoadFactory.loadGameObject(path, ActivityHallConfig.class, DataFactory.ACTIVITY_HALL);
            LoadFactory.loadGameObject(path, GuideConfig.class, DataFactory.GUIDE_TYPE);
            LoadFactory.loadGameObject(path, SevenActivitiesConfig.class, DataFactory.SEVEN_DAY_REWARD);
            LoadFactory.loadGameObject(path, SevenActivitiesRewardConfig.class, DataFactory.SEVEN_ACTIVITIES_REWARD);
            LoadFactory.loadGameObject(path, SevenTabConfig.class, DataFactory.SEVEN_TAB);
            LoadFactory.loadGameObject(path, TalentConfig.class, DataFactory.TALENT_BEAN);
            LoadFactory.loadGameObject(path, TalentLevelConfig.class, DataFactory.TALENT_LEVEL);
            LoadFactory.loadGameObject(path, TalentRefineConfig.class, DataFactory.TALENT_REFINE);
            LoadFactory.loadGameObject(path, TalentUpConfig.class, DataFactory.TALENT_UP);


            //以下两个不需要KEY值
            LoadFactory.loadGameObject(path, LocalizationConfig.class, 0);

        }catch (Exception e){
            e.printStackTrace();

            JOptionPane.showMessageDialog(null, "加载对象配置有错，请检查!");
            System.exit(0);
        }

    }


    private static void loadGameObject(String path, Class cls, int key) throws Exception
    {
        path = path + "/" + cls.getSimpleName().replace("Config", "");
        if(DataFactory.getInstance(LoadFactory.isTestLoad()).getDataList(key) != null)
        {
            LogUtils.error("Load " + cls.getSimpleName() + " Key Repeated Error -> key:" + key + " test:" + LoadFactory.isTestLoad());
            return;
        }

        InputStream input = null;
        try {
            input = LoadFactory.getInputStream(path);
            List<GameObject> datas = LoadUtils.loadFileVariables(input, cls);
            if(cls == LocalizationConfig.class)
            {
                DataFactory dataFactory = DataFactory.getInstance(LoadFactory.isTestLoad());
                LocalizationConfig localizationConfig = null;
                for(GameObject gameObject : datas)
                {
                    localizationConfig = (LocalizationConfig) gameObject;
                    if(ConfigFactory.LANGUAGE.equals(ConstantFactory.LANGUAGE_CHINESE))
                    {
                        dataFactory.addWord(localizationConfig.key.toLowerCase(), localizationConfig.Chinese);
                    }
                    else if(ConfigFactory.LANGUAGE.equals(ConstantFactory.LANGUAGE_CHINESETRADITIONAL))
                    {
                        dataFactory.addWord(localizationConfig.key.toLowerCase(), localizationConfig.ChineseTraditional);
                    }
                    else if(ConfigFactory.LANGUAGE.equals(ConstantFactory.LANGUAGE_ENGLISH))
                    {
                        dataFactory.addWord(localizationConfig.key.toLowerCase(), localizationConfig.English);
                    }
                }

                WordFactory.check(dataFactory);
            }
            else
            {
                Map<Integer,GameObject> map = new HashMap<>();
                for(GameObject gameObject : datas)
                {
                    if(map.get(gameObject.id) != null)
                    {
                        LogUtils.error("Load " + cls.getSimpleName() + " Repeated Error -> id:" + gameObject.id);
                        DataFactory.getInstance(LoadFactory.isTestLoad()).addError(cls.getSimpleName(), "id", "repeated", gameObject.id);
                    }

                    map.put(gameObject.id, gameObject);
                }

                DataFactory.getInstance(LoadFactory.isTestLoad()).addData(key, datas, map);

                if(key == DataFactory.PLAYER_LV_KEY)
                {
                    DataFactory.getInstance(LoadFactory.isTestLoad()).MAX_PLAYER_LV = datas.get(datas.size()-1).getId();
                }

                if(cls == InitDataConfig.class)
                {
                    for (GameObject config:datas){
                        ((InitDataConfig)config).init();
                    }
                }
            }

            LogUtils.info("Load " + cls.getSimpleName() + " Success!");

        } finally {
            try {
                if(input != null){
                    input.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
                LogUtils.error(e.getMessage());
            }
        }

    }




    private final static String CONFIG_NAME = "config.properties";

    public static void loadConfig()
    {
        LogUtils.info("【Load Config Start FileName=" + FIXED_CONFIG_PATH + CONFIG_NAME + "】");
        Properties properties = new Properties();
        InputStream input =  null;
        boolean isError = false;
        try {
            input = getInputStream(FIXED_CONFIG_PATH + CONFIG_NAME);
            properties.load(input);

            input = getInputStream(FIXED_CONFIG_PATH + CONFIG_NAME);
            ConfigFactory.ENGINE = properties.get("ENGINE").toString().trim();
            ConfigFactory.LANGUAGE = properties.get("LANGUAGE").toString().trim();
            ConfigFactory.SERVER_PORT_MAIN = Integer.parseInt(properties.get("SERVER_PORT_MAIN").toString().trim());
            ConfigFactory.SERVER_PORT_GM = Integer.parseInt(properties.get("SERVER_PORT_GM").toString().trim());
            ConfigFactory.SERVER_PORT_RMI = Integer.parseInt(properties.get("SERVER_PORT_RMI").toString().trim());
            ConfigFactory.SERVER_PORT_RMI_HIDE = Integer.parseInt(properties.get("SERVER_PORT_RMI_HIDE").toString().trim());
            ConfigFactory.SERVER_URL_RMI = properties.get("SERVER_URL_RMI").toString().trim();
            ConfigFactory.SERVER_URL_RMI = MessageFormat.format(ConfigFactory.SERVER_URL_RMI, CoreUtils.getInternetIp(), ConfigFactory.SERVER_PORT_RMI + "");

            ConfigFactory.LOG_PATH = properties.get("LOG_PATH").toString().trim();
            String[] ports = properties.get("SERVER_PORT_BATTLE").toString().trim().split(",");
            ConfigFactory.SERVER_PORT_BATTLE = new int[ports.length];
            for(int i = 0; i < ports.length; i++)
            {
                ConfigFactory.SERVER_PORT_BATTLE[i] = Integer.parseInt(ports[i]);
            }

            LogUtils.info("ENGINE--------------------【" + ConfigFactory.ENGINE + "】");
            LogUtils.info("LANGUAGE------------------【" + ConfigFactory.LANGUAGE + "】");
            LogUtils.info("SERVER_PORT_MAIN----------【" + ConfigFactory.SERVER_PORT_MAIN + "】");
            LogUtils.info("SERVER_PORT_GM------------【" + ConfigFactory.SERVER_PORT_GM + "】");
            LogUtils.info("SERVER_PORT_RMI-----------【" + ConfigFactory.SERVER_PORT_RMI + "】");
            LogUtils.info("SERVER_PORT_RMI_HIDE------【" + ConfigFactory.SERVER_PORT_RMI_HIDE + "】");
            LogUtils.info("SERVER_URL_RMI------------【" + ConfigFactory.SERVER_URL_RMI + "】");
            LogUtils.info("SERVER_PORT_BATTLE--------【" + Arrays.toString(ConfigFactory.SERVER_PORT_BATTLE) + "】");
            LogUtils.info("LOG_PATH------------------【" + ConfigFactory.LOG_PATH + "】");

            LogUtils.info("Load Config Success==============================");

        }catch (Exception e){
            e.printStackTrace();

            JOptionPane.showMessageDialog(null, "config.properties配置有错，请检查!");
            isError = true;
        }finally {
            if(input != null){
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

            if(isError)
            {
                LogUtils.error("加载出错，关闭服务器");
                System.exit(0);
            }
        }
    }
    private static final String PLATFORM_CONFIG_NAME = "platform.properties";

    public static boolean rewritePlatform(String content)
    {
        LogUtils.info("【rewrite Platform start FileName】" + FIXED_CONFIG_PATH + PLATFORM_CONFIG_NAME + "】");

        File file = null;
        try{
            if(PLATFORM_CONFIG_NAME.startsWith("C:") || PLATFORM_CONFIG_NAME.startsWith("D:")
                    || PLATFORM_CONFIG_NAME.startsWith("E:") || PLATFORM_CONFIG_NAME.startsWith("F:") || PLATFORM_CONFIG_NAME.startsWith("G:"))
                file = new File(PLATFORM_CONFIG_NAME);
            else
                file = new File(CoreUtils.getBasePath() + FIXED_CONFIG_PATH + PLATFORM_CONFIG_NAME);

            if(!file.exists())
                file = new File(CoreUtils.getRootPath() + FIXED_CONFIG_PATH + PLATFORM_CONFIG_NAME);

            if (!file.exists()){
                LogUtils.error(FIXED_CONFIG_PATH + PLATFORM_CONFIG_NAME + "文件不存在！");
                return false;
            }
            String filePath = file.getPath();
            file.delete();
            BufferedWriter out = new BufferedWriter(new FileWriter(filePath));
            out.write(content);
            out.close();
        }catch (Exception e){
            LogUtils.errorException(e);
            return false;
        }
        loadPlatform();
        return true;
    }

    public static void loadPlatform()
    {
        LogUtils.info("Load Platform Start FileName=" + FIXED_CONFIG_PATH + PLATFORM_CONFIG_NAME + "==========================>");
        Properties properties = new Properties();
        InputStream input =  null;
        try {
            input = getInputStream(FIXED_CONFIG_PATH + PLATFORM_CONFIG_NAME);
            properties.load(input);

            PlatformFactory.init(properties);

            PlatformFactory.showInfo(true);

//            PlatformFactory.WECHAT_USERINFO_URL = properties.getProperty("WECHAT_USERINFO_URL");
//            PlatformFactory.QQ_USERINFO_URL = properties.getProperty("QQ_USERINFO_URL");
//
//            PlatformFactory.XIAOMI_VERIFY_URL = properties.getProperty("XIAOMI_VERIFY_URL");
//            PlatformFactory.XIAOMI_APP_ID = properties.getProperty("XIAOMI_APP_ID");
//            PlatformFactory.XIAOMI_APP_SECRET = properties.getProperty("XIAOMI_APP_SECRET");
//
//            PlatformFactory.YJ_PRIVATE_KEY = properties.getProperty("YI_PRIVATE_KEY");
//            PlatformFactory.YJ_CHECK_LOGIN_URL = properties.getProperty("YJ_CHECK_LOGIN_URL");
//
//            PlatformFactory.BAIDU_CALLBACK_URL = properties.getProperty("BAIDU_CALLBACK_URL");
//            PlatformFactory.BAIDU_AKEY = properties.getProperty("BAIDU_AKEY");
//
//            PlatformFactory.QW_CHECK_LOGIN_URL = properties.getProperty("QW_CHECK_LOGIN_URL");
//            PlatformFactory.JT_CHECK_LOGIN_URL = properties.getProperty("JT_CHECK_LOGIN_URL");
//            PlatformFactory.JT_AKEY = properties.getProperty("JT_AKEY");
//            PlatformFactory.PP_CHECK_LOGIN_URL = properties.getProperty("PP_CHECK_LOGIN_URL");
//            PlatformFactory.PP_GAMEKEY = properties.getProperty("PP_GAMEKEY");
//            PlatformFactory.PP_GAMEID = properties.getProperty("PP_GAMEID");
//            PlatformFactory.PP_PAY_KEY = properties.getProperty("PP_PAY_KEY");
//            PlatformFactory.PP_CHECK_LOGIN_URL_PARAM = properties.getProperty("PP_CHECK_LOGIN_URL_PARAM");
//
//            LogUtils.info("TENCENT_COS_APP_ID--------【" + PlatformFactory.TENCENT_COS_APP_ID + "】");
//            LogUtils.info("TENCENT_COS_SECRET_ID-----【" + PlatformFactory.TENCENT_COS_SECRET_ID + "】");
//            LogUtils.info("TENCENT_COS_SECRET_KEY----【" + PlatformFactory.TENCENT_COS_SECRET_KEY + "】");
//            LogUtils.info("TENCENT_COS_BUCKET--------【" + PlatformFactory.TENCENT_COS_BUCKET + "】");
//            LogUtils.info("TENCENT_COS_REGION--------【" + PlatformFactory.TENCENT_COS_REGION + "】");
//
//            LogUtils.info("PHONE_MESSAGE_SIGN--------【" + PlatformFactory.PHONE_MESSAGE_SIGN + "】");
//            LogUtils.info("PHONE_MESSAGE_CONTENT-----【" + PlatformFactory.PHONE_MESSAGE_CONTENT + "】");
//            LogUtils.info("PHONE_MESSAGE_URL---------【" + PlatformFactory.PHONE_MESSAGE_URL + "】");
//            LogUtils.info("PHONE_MESSAGE_CAPTCHA-----【" + PlatformFactory.PHONE_MESSAGE_CAPTCHA + "】");
//
//            LogUtils.info("WECHAT_USERINFO_URL-------【" + PlatformFactory.WECHAT_USERINFO_URL + "】");
//            LogUtils.info("QQ_USERINFO_URL-----------【" + PlatformFactory.QQ_USERINFO_URL + "】");
//
//            LogUtils.info("XIAOMI_VERIFY_URL---------【" + PlatformFactory.XIAOMI_VERIFY_URL + "】");
//            LogUtils.info("XIAOMI_APP_ID-------------【" + PlatformFactory.XIAOMI_APP_ID + "】");
//            LogUtils.info("XIAOMI_APP_SECRET---------【" + PlatformFactory.XIAOMI_APP_SECRET + "】");
//
//            LogUtils.info("YJ_PRIVATE_KEY------------【" + PlatformFactory.YJ_PRIVATE_KEY + "】");
//            LogUtils.info("YJ_CHECK_LOGIN_URL--------【" + PlatformFactory.YJ_CHECK_LOGIN_URL + "】");
//
//            LogUtils.info("BAIDU_CALLBACK_URL--------【" + PlatformFactory.BAIDU_CALLBACK_URL + "】");
//            LogUtils.info("BAIDU_AKEY----------------【" + PlatformFactory.BAIDU_AKEY + "】");
//            LogUtils.info("QW_CHECK_LOGIN_URL--------【" + PlatformFactory.QW_CHECK_LOGIN_URL + "】");
//            LogUtils.info("JT_CHECK_LOGIN_URL--------【" + PlatformFactory.JT_CHECK_LOGIN_URL + "】");
//            LogUtils.info("JT_AKEY-------------------【" + PlatformFactory.JT_AKEY + "】");
//            LogUtils.info("PP_CHECK_LOGIN_URL--------【" + PlatformFactory.PP_CHECK_LOGIN_URL + "】");
//            LogUtils.info("PP_GAMEKEY----------------【" + PlatformFactory.PP_GAMEKEY + "】");
//            LogUtils.info("PP_GAMEID-----------------【" + PlatformFactory.PP_GAMEID + "】");
//            LogUtils.info("PP_PAY_KEY----------------【" + PlatformFactory.PP_PAY_KEY + "】");
//
//            LogUtils.info("PAY_INIT------------------【" + HttpFactory.PAY_INIT + "】");
//            LogUtils.info("PAY_YJ_CHECK--------------【" + HttpFactory.PAY_YJ_CHECK + "】");
//            LogUtils.info("PAY_NOTIFY_APPLEPAY-------【" + HttpFactory.PAY_NOTIFY_APPLEPAY + "】");
//            LogUtils.info("PLAYER_UPDATE_RECORD------【" + HttpFactory.PLAYER_UPDATE_RECORD + "】");
//            LogUtils.info("PLAYER_UPDATE_RECORD2-----【" + HttpFactory.PLAYER_UPDATE_RECORD2 + "】");
//            LogUtils.info("SERVER_CHANGE_STATUS------【" + HttpFactory.SERVER_CHANGE_STATUS + "】");

            LogUtils.info("Load Platform Success==========================>");

        }catch (Exception e){
            e.printStackTrace();
            JOptionPane.showMessageDialog(null, "platform.properties配置有错，请检查!");
            System.exit(0);
        }finally {
            if(input != null){
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 加载微信支付配置,只在认证服调用
     */
    public static void loadTenpayConfig()
    {
        final String TENPAY_CONFIG_NAME = FIXED_CONFIG_PATH + "pay-tenpay.properties";
        LogUtils.info("Load Tenpay Start FileName=" + TENPAY_CONFIG_NAME + "==========================>");
        Properties properties = new Properties();
        InputStream input =  null;
        try {
            input = getInputStream(TENPAY_CONFIG_NAME);
            properties.load(input);

            TenpayConfig.init(properties);

            LogUtils.info("\n" + TenpayConfig.showInfo());

            LogUtils.info("Load Tenpay Success==========================>");

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(input != null){
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    /**
     * 加载支付宝支付配置,只在认证服调用
     */
    public static void loadAlipayConfig()
    {
        final String ALIPAY_CONFIG_NAME = FIXED_CONFIG_PATH + "pay-alipay.properties";
        LogUtils.info("Load Alipay Start FileName=" + ALIPAY_CONFIG_NAME + "==========================>");
        Properties properties = new Properties();
        InputStream input =  null;
        try {
            input = getInputStream(ALIPAY_CONFIG_NAME);
            properties.load(input);

            AlipayConfig.init(properties);

            LogUtils.info("\n" + AlipayConfig.showInfo());

            LogUtils.info("Load Alipay Success==========================>");

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if(input != null){
                try {
                    input.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }


    public static boolean isTestLoad() {
        return testLoad;
    }

    public static void setTestLoad(boolean testLoad) {
        LoadFactory.testLoad = testLoad;
    }

}
